﻿using Logistics.Recipients;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Logistics.Web.Controllers
{
    public class ClaimController : Controller
    {
        // GET: ClaimController
        public ActionResult ClaimIndex()
        {
            return View();
        }
        private readonly IClaimAppService _claimAppService;

        public ClaimController(IClaimAppService claimAppService)
        {
            _claimAppService = claimAppService;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task DeleteAsyncc(int id)
        {
            var i = _claimAppService.DeleteAsync(id);
            return i;
        }
        /// <summary>
        /// 查看视图
        /// </summary>
        /// <returns></returns>
        public ActionResult GetclaimIndex(int id)
        {
            ViewBag.Id = id;
            return View();
        }
        /// <summary>
        /// 反填视图
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult PutclaimIndex(int id)
        {
            ViewBag.Id = id;
            return View();
        }
        public IActionResult Updates(ClaimDto Claim)
        {
            var claim = _claimAppService.UpdateAsync(Claim);
            return Ok(claim);
        }

        /// <summary>
        /// 查看详情/反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task<ClaimDto> GetAsyncc(int id)
        {
            var claim = _claimAppService.GetAsync(id);
            return claim;
        }
        /// <summary>
        /// 添加视图
        /// </summary>
        /// <returns></returns>
        public ActionResult PostclaimIndex()
        {
            return View();
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="Procurement"></param>
        /// <returns></returns>
        public IActionResult Add(ClaimDto claim)
        {
            var i = _claimAppService.CreateAsync(claim).Result;
            return Ok(i);
        }

        /// <summary>
        /// 主页显示
        /// </summary>
        /// <returns></returns>
        public ActionResult ClaimListIndex()
        {
            return View();
        }

        // GET: ApproveController/Details/5
        public JsonResult ShowProcurementAsynccc(GetClaimListDto getClaimListDto)
        {
            var Procurements = _claimAppService.GetClaimListAsync(getClaimListDto).Result;

            return Json(new { data = Procurements.Items, count = Procurements.TotalCount, code = "0", msg = "" });
        }
    }
}
